
// 56.合并区间
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        int n = intervals.size();

        sort(intervals.begin() , intervals.end());
        vector<int> prev = intervals[0];
        vector<vector<int>> ret;
        for(int i = 1 ; i < n ; i++)
        {
            if(prev[0] <= intervals[i][0] && prev[1] >= intervals[i][1]) continue;
            if(prev[1] < intervals[i][0])
            {
                ret.push_back(prev);
                prev = intervals[i];
            }   
            else
                prev[1] = intervals[i][1];
        }
        ret.push_back(prev);
        return ret;
    }
};